package com.mydesign.demo.model;


import org.springframework.transaction.interceptor.TransactionAspectSupport;


public class ReturnResult {


    private long total;

    private Object data;

    private String code;

    private String msg;

    public ReturnResult(long total, Object data, String code, String msg) {
        this.total = total;
        this.data = data;
        this.code = code;
        this.msg = msg;
    }
    public ReturnResult(Object data, String code, String msg) {
        this.data = data;
        this.code = code;
        this.msg = msg;
    }
    public ReturnResult(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }


    public ReturnResult() {
    }

    public static ReturnResult success(){
        return new ReturnResult(ReturnMsg.SUCCESS.getCode(),ReturnMsg.SUCCESS.getMsg());
    }
    public static ReturnResult error(){
        return new ReturnResult(ReturnMsg.ERROR.getCode(),ReturnMsg.ERROR.getMsg());
    }
    public static ReturnResult permissions(){
        return new ReturnResult(ReturnMsg.PERMISSIONS.getCode(),ReturnMsg.PERMISSIONS.getMsg());
    }
    public static ReturnResult notLogin(){
        return new ReturnResult(ReturnMsg.NOTLOGIN.getCode(),ReturnMsg.NOTLOGIN.getMsg());
    }
//    public static ReturnResult result(PageInfo pageInfo){
//        return new ReturnResult(pageInfo.getTotal(),pageInfo.getList(),ReturnMsg.SUCCESS.getCode(),ReturnMsg.SUCCESS.getMsg());
//    }
    //返回失败并回滚
    public static ReturnResult errortRollback(String msg){
        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        return new ReturnResult(ReturnMsg.ERROR.getCode(),msg);
    }
    public static ReturnResult dataSuccess(Object data){
        return new ReturnResult(data,ReturnMsg.SUCCESS.getCode(),ReturnMsg.SUCCESS.getMsg());
    }




    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}
